package o;

import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.hmf.annotation.ApiDefine;
import com.huawei.hmf.annotation.Singleton;
import o.cwl.b;

@ApiDefine(uri = cvy.class)
@Singleton
public class cwc implements cvy {
    private static cwf ˋ = new cwf();

    class e implements b {
        private int ˊ;
        final /* synthetic */ cwc ˎ;
        private cvt ˏ;
        private AsyLoader ॱ;

        public e(cwc o_cwc, cvt o_cvt, AsyLoader o_cwa, int i) {
            this.ˎ = o_cwc;
            this.ˏ = o_cvt;
            this.ॱ = o_cwa;
            this.ˊ = i;
        }

        private String ˋ(int i) {
            String str = "";
            if (i == 1) {
                return "invokeServer";
            }
            if (i == 2) {
                return "invokeServerForList";
            }
            return str;
        }

        public void ॱ(boolean z) {
            String ˋ = ˋ(this.ˊ);
            if (z) {
                cvp.ˎ.ˋ("ServerAgentImpl", ˋ + "[" + this.ˏ.getMethod_() + "] will excute again,GRS get urls Successed.");
            } else {
                cvp.ˎ.ˊ("ServerAgentImpl", ˋ + " ERROR:GRS get urls Failed:");
            }
            if (this.ˊ == 1) {
                this.ˎ.ˊ(this.ˏ, this.ॱ);
            } else if (this.ˊ == 2) {
                this.ˎ.ˎ(this.ˏ, this.ॱ);
            }
        }
    }

    public AsyLoader ˊ(cvt o_cvt, IServerCallBack iServerCallBack) {
        AsyLoader o_cwi = new cwi(o_cvt, iServerCallBack);
        eqm ˊ = eqk.ˊ();
        int i = (ˊ == null || !ˊ.ॱ()) ? 0 : 1;
        if (!dof.ˋ(cvx.ˎ(o_cvt.targetServer)) && i == 0) {
            return ˊ(o_cvt, o_cwi);
        }
        new cwl().ˊ(o_cvt, new e(this, o_cvt, o_cwi, 1));
        return o_cwi;
    }

    public ResponseBean ˏ(cvt o_cvt) {
        eqm ˊ = eqk.ˊ();
        Object obj = (ˊ == null || !ˊ.ॱ()) ? null : 1;
        String ˎ = cvx.ˎ(o_cvt.targetServer);
        cwl o_cwl = new cwl();
        if (dof.ˋ(ˎ) || obj != null) {
            return o_cwl.ˋ(o_cvt);
        }
        return o_cwl.ˋ(o_cvt, ˎ);
    }

    public AsyLoader ॱ(cvt o_cvt, IServerCallBack iServerCallBack) {
        String ˎ = cvx.ˎ(o_cvt.targetServer);
        AsyLoader o_cwi = new cwi(o_cvt, iServerCallBack);
        eqm ˊ = eqk.ˊ();
        Object obj = (ˊ == null || !ˊ.ॱ()) ? null : 1;
        if (!dof.ˋ(ˎ) && obj == null) {
            return ˎ(o_cvt, o_cwi);
        }
        new cwl().ˊ(o_cvt, new e(this, o_cvt, o_cwi, 2));
        return o_cwi;
    }

    private AsyLoader ˊ(cvt o_cvt, AsyLoader o_cwa) {
        o_cvt.setUrl(cvx.ˎ(o_cvt.targetServer));
        ˊ(o_cwa, o_cvt);
        return o_cwa;
    }

    private AsyLoader ˎ(cvt o_cvt, AsyLoader o_cwa) {
        cvp.ˎ.ˋ("ServerAgentImpl", "invokeServerForList, method:" + o_cvt.getMethod_() + ", cacheSize:" + ˋ.ॱ());
        o_cvt.setUrl(cvx.ˎ(o_cvt.targetServer));
        if ("server.store".equals(o_cvt.targetServer)) {
            ˋ.ˊ(eps.ॱ, o_cwa);
        } else {
            ˋ.ˊ(eps.ˎ, o_cwa);
        }
        return o_cwa;
    }

    private void ˊ(AsyLoader o_cwa, cvt o_cvt) {
        cvp.ˎ.ˋ("ServerAgentImpl", "executeTask, method:" + o_cvt.getMethod_() + ", ActiveCount:" + eps.ˋ.getActiveCount() + ", TaskCount:" + eps.ˋ.getTaskCount());
        if (o_cvt.getReqContentType() == o.cvu.RequestBodyType.FILE) {
            o_cwa.ˏ(eps.ʻ);
        } else if (o_cvt.isSerial()) {
            o_cwa.ˏ(eps.ˏ);
        } else {
            o_cwa.ˏ(eps.ˋ);
        }
    }

    public boolean ॱ(int i) {
        return cwi.ˏ(i);
    }

    public boolean ˎ(AsyncTask asyncTask) {
        return asyncTask == null || Status.RUNNING != asyncTask.getStatus();
    }

    public void ˎ() {
        cwf.ˋ();
        cvp.ˎ.ˋ("ServerAgentImpl", "clear http cache completed.");
    }
}
